class WebTicket < ActiveRecord::Base
  belongs_to :order, :class_name => 'WebOrder', :foreign_key => 'web_order_id'

  def self.saveWebTicket(orderid,pnr,pass_name,pass_tel,id_card,price,airdrome_tax,fuel_tax,insurance_number)
    begin
      ticket = WebTicket.new
      ticket.pnr = pnr
      ticket.web_order_id = orderid.to_i
      ticket.ticket_no = ""    #票号
      ticket.pass_name = pass_name if pass_name
      ticket.pass_tel = pass_tel if pass_tel
      ticket.pass_card_id = id_card if id_card
      ticket.insurance_number = insurance_number.to_i if insurance_number
      ticket.price = price.to_i if price
      ticket.airdrome_tax = airdrome_tax.to_i if airdrome_tax
      ticket.fuel_tax = fuel_tax.to_i if fuel_tax
      ticket.status = Constants::TICKET_STATUS_WQR
      ticket.total_price = ticket.price + (Constants::DEFAULT_INSURANCE_PRICE*ticket.insurance_number) + ticket.airdrome_tax + ticket.fuel_tax
      if ticket.save
        return ticket.id
      end
      return nil
    rescue Exception => e
      logger.error("model WebTicket saveWebTicket e="+e.message)
      return nil
    end
  end
end
